<?php

namespace App\Http\Controllers\System\Testing;

use App\Http\Controllers\Controller as BaseController;

class Controller extends BaseController
{

    /**
     * 参数验证【玩家账号】
     *
     * @return array
     */
    protected function validateAccount(): array
    {
        return [
            ['account_id' => ['required', 'regex:/^[a-zA-Z0-9_\-\.]+$/u', 'between:1,64']],
            ['account_id.regex' => trans('validation.alpha_dash')],
        ];
    }

    /**
     * 参数验证【币种金额】
     *
     * @return array
     */
    protected function rulesAmount(): array
    {
        return [
            'amount' => [
                'required', 'numeric', 'between:0,100000000',
                function ($attribute, $value, $fail) {
                    // 获取小数点位数
                    $precision = config('system.numeral.precision');
                    // 小数点位数判断
                    if ($value != round($value, $precision, PHP_ROUND_HALF_DOWN)) {
                        $fail(trans('validation.numeric_precision', ['precision' => $precision]));
                    }
                }
            ]
        ];
    }
}
